var net = require('net')
// 检测端口是否被占用
function portIsOccupied (port, onSuccess, onError) {
  // 创建服务并监听该端口
  var server = net.createServer().listen(port)

  server.on('listening', function () { // 执行这块代码说明端口未被占用
    server.close() // 关闭服务
    console.log('The port[' + port + '] is available.') // 控制台输出信息

    onSuccess()
  })

  server.on('error', function (err) {
    if (err.code === 'EADDRINUSE') { // 端口已经被使用
      console.log('The port[' + port + '] is occupied, please change other port.')

      onError()
    }
  })
}

portIsOccupied(3200, function () {

}, function () {

})

var ip = require('ip')
console.log(ip.address() )